﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace GameLib {

    public class Sprite : IFocusable {
        #region IFocusable Members

        Vector2 IFocusable.Position {
            get { return Position; }
        }

        #endregion

        private string _textureAsset;
        private Texture2D _token;

        [ContentSerializerIgnore]
        public Vector2 Position;
        [ContentSerializerIgnore]
        public Vector2 Origin;
        [ContentSerializerIgnore]
        public float Scale;
        [ContentSerializerIgnore]
        public float Rotation;

        [ContentSerializerIgnore]
        public Texture2D Back { get; set; }

        [ContentSerializerIgnore]
        public Texture2D Texture {
            get { return _token; }
            set { 
                _token = value;
                if (_token != null) {
                    this.Origin = new Vector2(_token.Width / 2, _token.Height / 2);
                }
            }
        }

        [ContentSerializerIgnore]
        public string TextureAsset {
            get { return _textureAsset; }
            set { _textureAsset = value; }
        }

        public virtual void Load(ContentManager content) {
            _token = content.Load<Texture2D>(_textureAsset);
        }

        public Sprite() {
            this.Position = Vector2.Zero;
            this.Origin = Vector2.Zero;
            this.Scale = 1f;
            this.Rotation = 0f;
        }

        public Sprite(Texture2D texture):this() {
            this.Texture = texture;
        }
    }
}
